package com.braveo.dict;


import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class HistoryView extends ListActivity {
	private BraveRememberDbAdapter mDbHelper;
	private Cursor mWordCursor;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.setContentView(R.layout.old_word_choose);

		mDbHelper = BraveRememberDbAdapter.getInstance(this);
        //mDbHelper.open();
        
        fillData();
 	}
	
	private void fillData() {		
		Cursor c = mWordCursor = mDbHelper.getAllWords();
		
		this.startManagingCursor(c);
		
		String[] from = new String [] { "Word"};
		int[] to   = new int[]     { R.id.row_text};
		
		SimpleCursorAdapter ad = new SimpleCursorAdapter(this, R.layout.text_row, c, from, to);
		setListAdapter(ad);
		
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		super.onConfigurationChanged(newConfig);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		Cursor c = mWordCursor;
		
		c.moveToPosition(position);

		Intent i = new Intent();
		i.putExtra("WORD", c.getString(c.getColumnIndexOrThrow("Word")));
		setResult(RESULT_OK, i);
		finish();		
	}
	
}
